<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import customerAddress from '@/api/customers/customerAddress'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'
import dictHelp from '@/utils/dicthelp'

const crudRef = ref()

const options = reactive({
  id: 'customer_address',
  pageLayout: 'fixed',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: customerAddress.getList,
  recycleApi: customerAddress.getRecycleList,
  tabs: {
    dataIndex: "type",
    searchKey: "type",
    // defaultKey: 1
  },

  add: {
    show: true,
    api: customerAddress.save,
    auth: ['customers:customerAddress:save']
  },
  edit: {
    show: true,
    api: customerAddress.update,
    auth: ['customers:customerAddress:update']
  },
  delete: {
    show: true,
    api: customerAddress.deletes,
    auth: ['customers:customerAddress:delete'],
    realApi: customerAddress.realDeletes,
    realAuth: ['customers:customerAddress:realDeletes']
  },
  recovery: {
    show: true,
    api: customerAddress.recoverys,
    auth: ['customers:customerAddress:recovery']
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "用户",
    dataIndex: "customer_id",
    formType: "select",
    search: true,
    dict:dictHelp.customer,
    commonRules: {
      required: true,
      message: "请输入用户"
    }
  },
  {
    title: "地址简称",
    dataIndex: "address_name",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入地址简称"
    }
  },
  {
    title: "类型",
    dataIndex: "type",
    formType: "select",
    search: true,
    commonRules: {
      required: true,
      message: "请输入类型"
    },
    dict: {
      name: "addressType",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    }
  },
  {
    title: "联系人",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入联系人"
    }
  },
  {
    title: "公司",
    dataIndex: "company",
    formType: "input"
  },
  {
    title: "电话",
    dataIndex: "tel",
    formType: "input"
  },
  {
    title: "手机",
    dataIndex: "mobile",
    formType: "input",
    search: true
  },
  {
    title: "地址一",
    dataIndex: "address_1",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入地址"
    }
  },
  {
    title: "地址二",
    dataIndex: "address_2",
    formType: "input",
  },
  {
    title: "地址三",
    dataIndex: "address_3",
    formType: "input",
  },
  {
    title: "城市",
    dataIndex: "city",
    formType: "input",
  },
  {
    title: "省/州",
    dataIndex: "state",
    formType: "input"
  },
  {
    title: "邮编",
    dataIndex: "postcode",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入邮编"
    }
  },
  {
    title: "国家",
    dataIndex: "country",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入国家"
    }
  },
  {
    title: "默认地址",
    dataIndex: "default",
    formType: "switch",
    checkedValue: "1",
    uncheckedValue: "0"
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'customers:customerAddress' } </script>